﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MyFinanceManager.Controls;
using MyFinanceManager.Objects;

namespace MyFinanceManager
{
    public partial class ucMileometer : FiringUserControl
    {
        public int Value
        {
            get
            {
                int value = 0;
                value += this.upAndDowner5.Value * 1;
                value += this.upAndDowner4.Value * 10;
                value += this.upAndDowner3.Value * 100;
                value += this.upAndDowner2.Value * 1000;
                value += this.upAndDowner1.Value * 10000;
                value += this.upAndDowner0.Value * 100000;
                return value;
            }
        }

        public ucMileometer()
        {
            InitializeComponent();

            if (Database.LastMileometer.Length > 5)
                this.upAndDowner0.Value = int.Parse(Database.LastMileometer[0].ToString());
            if (Database.LastMileometer.Length > 4)
                this.upAndDowner1.Value = int.Parse(Database.LastMileometer[1].ToString());
            if (Database.LastMileometer.Length > 3)
                this.upAndDowner2.Value = int.Parse(Database.LastMileometer[2].ToString());
            if (Database.LastMileometer.Length > 2)
                this.upAndDowner3.Value = int.Parse(Database.LastMileometer[3].ToString());
            if (Database.LastMileometer.Length > 1)
                this.upAndDowner4.Value = int.Parse(Database.LastMileometer[4].ToString());
            if (Database.LastMileometer.Length > 0)
                this.upAndDowner5.Value = int.Parse(Database.LastMileometer[5].ToString());

            this.upAndDowner0.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner1.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner2.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner3.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner4.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
            this.upAndDowner5.ValueChanged += new EventHandler(upAndDowner_ValueChanged);
        }

        void upAndDowner_ValueChanged(object sender, EventArgs e)
        {
            FireNewValueAvailable(this.Value.ToString("N0"));
        }

    }
}
